import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import * as elementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import '@/assets/styles/index.scss'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import '@/assets/styles/element-plus/element-variables.scss'
// import * as echarts from 'echarts'
const vm = createApp(App)
vm.use(elementPlus).use(router).mount('#app')

// 全局挂载 echarts
// vm.config.globalProperties.$echarts = echarts

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
	vm.component(key, component)
}
router.beforeEach((to, from, next) => {
	if (to.matched.some(res => res.meta.requireAuth)) { // 验证是否需要登陆
	  var id=window.sessionStorage.getItem('userId');
	  if (id) { // 查询本地存储信息是否已经登陆
		next();
	  } else {
		next({
		  path: '/login', // 未登录则跳转至login页面
		  redirect:  '/home' // 登陆成功后回到当前页面，这里传值给login页面，to.fullPath为当前点击的页面
		  });
	  }
	} else {
	  next();
	}
  })